package m.base.model;

import m.common.model.*;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import m.system.cache.FlushCache;
import manage.model.AdminLogin;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@TableMeta(name = "os_admin_login", description = "用户|继承登录账号")
public class UserInfo extends AdminLogin implements FlushCache, MigrationModel {
    @Override
    public List<String> migrationOidList(String storeOid) throws Exception {
        return ModelQueryList.getModelList(this.getClass(),new String[]{"oid"},null,
            QueryCondition.eq("store.oid",storeOid))
            .stream().map(Model::getOid).collect(Collectors.toList());
    }
    public final static String OperType_Stock="A";
    public final static String OperType_Finance="C";
    public final static String OperType_Store="D";
    public final static String OperType_Collect="E";
    @FieldMeta(name="oper_type",type= FieldType.STRING,length=20,description="用户类型",dictOption = "A:库存管理,C:财务管理,D:商户管理,E:统计汇总")
    private String[] operType;
    @FieldMeta(name="phone",type= FieldType.STRING,length=20,description="联系电话")
    private String phone;
    @FieldMeta(name="create_store_oid",type= FieldType.STRING,length=50,description="创建商户主键")
    private String createStoreOid;
    @LinkTableMeta(name="store_oid",table= StoreInfo.class,description="所属商户")
    private StoreInfo store;

    public StoreInfo getStore() {
        return store;
    }

    public void setStore(StoreInfo store) {
        this.store = store;
    }

    public String getCreateStoreOid() {
        return createStoreOid;
    }

    public void setCreateStoreOid(String createStoreOid) {
        this.createStoreOid = createStoreOid;
    }

    public String[] getOperType() {
        return operType;
    }

    public void setOperType(String[] operType) {
        this.operType = operType;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public UserInfo getCacheModel(String key) throws Exception {
        return ModelQueryList.getModel(UserInfo.class,key,"*");
    }
}
